#!/usr/bin/python
#
# Copyright (C) 2008 rambla.be
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

""" Contains the objects required for RATS input resource access. """

try:
  from xml.etree import cElementTree as ElementTree
except ImportError:
  try:
    import cElementTree as ElementTree
  except ImportError:
    from elementtree import ElementTree

import ratom
import rawsc
from rawsc import RAWS_NAMESPACE
from rawsc.rats import *

class InputParams(rawsc.RawsParams):
    """ Handler for the <raws:params> element (= sub-element of atom:content). """
    _children = {}
    _children['{%s}id' % rawsc.RAWS_NAMESPACE] = ('id', Id)
    _children['{%s}name' % RAWS_NAMESPACE] = ('name', Name)
    _children['{%s}description' % RAWS_NAMESPACE] = ('description', Description)
    _children['{%s}base_uri' % rawsc.RAWS_NAMESPACE] = ('base_uri', BaseUri)
    _children['{%s}method' % RAWS_NAMESPACE] = ('method', Method)
    _children['{%s}cdn' % RAWS_NAMESPACE] = ('cdn', Cdn)
    _children['{%s}max_size' % RAWS_NAMESPACE] = ('max_size', MaxSize)
    _children['{%s}params' % RAWS_NAMESPACE] = ('params', Params)

    def __init__(self, id=None, name=None, description=None, base_uri=None, method=None, cdn=None, max_size=None, params=None):
        rawsc.RawsParams.__init__(self, extension_elements=None, extension_attributes=None)
        self.id = Id(text = id)
        self.name = Name(text = name)
        self.description = Description(text = description)
        self.base_uri = BaseUri(text = base_uri)
        self.method = Method(text = method)
        self.cdn = Cdn(text = cdn)
        self.max_size = MaxSize(text = max_size)
        self.params = Params(text = params)

def InputParamsFromString(xml_string):
    return ratom.CreateClassFromXMLString(InputParams, xml_string)   


class InputContent(rawsc.RawsContent):
    """ Handler for the atom:content element, in a RAWS context. """
    _children = ratom.AtomBase._children.copy()
    _children['{%s}params' % (RAWS_NAMESPACE)] = ('params', InputParams)
    
    params = None
    
    def __init__(self, params=None):
        rawsc.RawsContent.__init__(self, extension_elements=None, extension_attributes=None)
        self.params = InputParams()
        if params:
            self.params = params
    
def InputContentFromString(xml_string):
    return ratom.CreateClassFromXMLString(InputContent, xml_string)   
    

class InputEntry(rawsc.RawsEntry):
    """ Handler for an entry that is returned by the RATS input resource."""
    _children = rawsc.RawsEntry._children.copy()
    _children['{%s}content' % ratom.ATOM_NAMESPACE] = ('content', InputContent)

    def __init__(self, author=None, category=None, atom_id=None, link=None, published=None, title=None, updated=None, content = None, extension_elements=None, extension_attributes=None):
        rawsc.RawsEntry.__init__(self, author=author, category=category, atom_id=atom_id, link=link, published=published, title=title, updated=updated,
                                extension_elements=extension_elements, extension_attributes=extension_attributes)
        self.content = InputContent()
        if content:
            self.content = content

def InputEntryFromString(xml_string):
    return ratom.CreateClassFromXMLString(InputEntry, xml_string)
    

class InputFeed(rawsc.RawsFeed, rawsc.LinkFinder):
    """ Handler for a feed that is returned by the RATS input resource."""
    _children = rawsc.RawsFeed._children.copy()
    _children['{%s}entry' % ratom.ATOM_NAMESPACE] = ('entry', [InputEntry])

def InputFeedFromString(xml_string):
  return ratom.CreateClassFromXMLString(InputFeed, xml_string)

